/*
 * @Description: 通用title props
 * @Author: Rfan
 * @Date: 2023-01-05 10:39:02
 * @LastEditTime: 2023-01-05 10:40:40
 */

import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
import { is } from 'bpmn-js/lib/util/ModelUtil';
import { fetchDepartmentListByUnitId } from '@/api/department';
import { getOptions } from './Helper';

let selectOptions = [
  { name: 'yi', value: 1 },
  { name: 'er', value: 2 }
];

setTimeout(() => {
  selectOptions = [
    { name: 'san', value: 3 },
    { name: 'si', value: 4 }
  ];
}, 6000);

const TitleProps = (group, element, translate) => {
  // fetchDepartmentListByUnitId(4).then((res) => {
  //   selectOptions = getOptions(
  //     res.data.map((item) => ({ id: item.id, name: item.deptName, value: item.id })),
  //     translate
  //   );
  // });
  if (is(element, 'bpmn:UserTask')) {
    // department
    group.entries.push(
      {
        id: 'department',
        html: `<input />`
      }
      // entryFactory.selectBox(translate, {
      //   id: 'department',
      //   label: translate('department'),
      //   selectOptions,
      //   modelProperty: 'department',
      //   setControlValue: true
      // })
    );

    // Assignee
    group.entries.push(
      entryFactory.selectBox(translate, {
        id: 'assignee',
        label: translate('Assignee'),
        selectOptions: [
          { value: '', name: translate('<none>') },
          { name: 'BPMN', value: 1 },
          { name: 'CMMN', value: 'cmmn' }
        ],
        modelProperty: 'assignee'
      })
    );

    // Candidate Users
    group.entries.push(
      entryFactory.textField(translate, {
        id: 'candidateUsers',
        label: translate('Candidate Users'),
        modelProperty: 'candidateUsers'
      })
    );

    // Candidate Groups
    group.entries.push(
      entryFactory.textField(translate, {
        id: 'candidateGroups',
        label: translate('Candidate Groups'),
        modelProperty: 'candidateGroups'
      })
    );
  }
};

export default TitleProps;
